//
//  BHTabBarViewController.m
//  xinlangweibo0621
//
//  Created by boldseas on 2017/6/21.
//  Copyright © 2017年 renbohan. All rights reserved.
//

//随机色
#define BHRandomColor BHColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

//RGB颜色
#define BHColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]


#import "BHTabBarViewController.h"
#import "BHHomeViewController.h"
#import "BHMessageViewController.h"
#import "BHDiscoverViewController.h"
#import "BHProfileViewController.h"
#import "BHNavigationController.h"
#import "BHTabBar.h"

@interface BHTabBarViewController ()

@end

@implementation BHTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    BHHomeViewController *home = [[BHHomeViewController alloc]init];
    home.view.backgroundColor = [UIColor whiteColor];
    [self addchildVc:home title:@"首页" image:@"tabbar_home" selectImage:@"tabbar_home_selected"];
    
    BHMessageViewController *message = [[BHMessageViewController alloc]init];
    [self addchildVc:message title:@"消息" image:@"tabbar_message_center" selectImage:@"tabbar_message_center_selected"];
    
    BHDiscoverViewController *discover = [[BHDiscoverViewController alloc]init];
    [self addchildVc:discover title:@"发现" image:@"tabbar_discover" selectImage:@"tabbar_discover_selected"];
    
    BHProfileViewController *profile = [[BHProfileViewController alloc]init];
    [self addchildVc:profile title:@"我" image:@"tabbar_profile" selectImage:@"tabbar_profile_selected"];
    
    BHTabBar *tabBar = [[BHTabBar alloc]init];
    
    [self setValue:tabBar forKeyPath:@"tabBar"];
    
    
    
}

- (void)addchildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage{
    childVc.title = title;
    
    
    
    childVc.tabBarItem.title = title;
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    NSMutableDictionary *selectattrs = [NSMutableDictionary dictionary];
    selectattrs[NSForegroundColorAttributeName] = BHColor(252, 129, 36);
    [childVc.tabBarItem setTitleTextAttributes:selectattrs forState:UIControlStateSelected];
    
    BHNavigationController *nav = [[BHNavigationController alloc]initWithRootViewController:childVc];
    nav.navigationItem.title = title;
    [self addChildViewController:nav];
}


@end
